package servlet;

import dao.UserDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author konley
 * @date 2020-06-17 15:37
 */
@WebServlet("/checkNameServlet")
public class CheckNameServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name = request.getParameter("name");
        System.out.println("name="+name);

        boolean b = new UserDao().checkName(name);
        if(name.equals("")){
            response.getWriter().println(3);
            System.out.println("return 3");
        }else{
            if(b){
                response.getWriter().println(1);
                System.out.println("return 1");
            }else{
                response.getWriter().println(0);
                System.out.println("return 0");
            }
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
